package top.lhj.security.example.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Service;
import top.lhj.security.example.config.DbUserDetailsManager;
import top.lhj.security.example.entity.UserEntity;
import top.lhj.security.example.mapper.UserMapper;
import top.lhj.security.example.service.UserService;

/**
 * @Author LiHaoJie
 * @Create 2024/2/3 10:46
 * @Version 1.0
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, UserEntity> implements UserService {
    
    @Autowired
    DbUserDetailsManager dbUserDetailsManager;
    
    @Override
    public boolean addUser(UserEntity userEntity) {
        UserDetails userDetails = User.withDefaultPasswordEncoder()
                .username(userEntity.getUsername())
                .password(userEntity.getPassword())
                .build();
        dbUserDetailsManager.createUser(userDetails);
        return true;
    }
}
